/* ** por compatibilidad se omiten tildes **
================================================================================
 TRABAJO PRACTICO 3 - System Programming - ORGANIZACION DE COMPUTADOR II - FCEN
================================================================================
  definicion de la tabla de descriptores globales
*/
#include "defines.h"

#include "gdt.h"
#include "tss.h"

gdt_entry gdt[GDT_COUNT] = {
	/* Descriptor nulo*/
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },

	/* Ejemplo del primer descriptor */
/*	(gdt_entry){
		(unsigned short) 0,
		(unsigned short) 0,
		(unsigned char) 0, 
		(unsigned char) 0, 
		(unsigned char) 0, 
		(unsigned char) 0, 
		(unsigned char) 0, 
		(unsigned char) 0,
		(unsigned char) 0,  
		(unsigned char) 0,  
		(unsigned char) 0,  
		(unsigned char) 0, 
		(unsigned char) 0 
	}*/
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },
	(gdt_entry){(unsigned int) 0x00000000, (unsigned int) 0x00000000 },

       /* Descriptor de segmento de codigo*/
        (gdt_entry){ 
                (unsigned short) 0xFFFF,        //limit 0:15    	(16 bits)
                (unsigned short) 0x0000,        //base 0:15             (16 bits)
                (unsigned char) 0x00,           //base 23:16    	(7 bits)
                (unsigned char) 0xA,            //type                  (4 bits)
                (unsigned char) 1,              //system                (1 bit)
                (unsigned char) 0,              //dpl                   (2 bits)
                (unsigned char) 1,              //present               (1 bit)
                (unsigned char) 0x7,            //limit_16_19   	(4 bit)
                (unsigned char) 0,              //avaible               (1 bit)
                (unsigned char) 0,              //l                     (1 bit)
                (unsigned char) 1,              //d/b                   (1 bit)
                (unsigned char) 1,              //granularity   	(1 bit)
                (unsigned char) 0x00            //base_31_24    	(16 bits)
        },

        /* Descriptor de segmento de datos*/
        (gdt_entry){ 
                (unsigned short) 0xFFFF,        //limit 0:15		(16 bits)
                (unsigned short) 0x0000,        //base 0:15             (16 bits)
                (unsigned char) 0x00,           //base 23:16		(7 bits)
                (unsigned char) 0x2,            //type                  (4 bits)
                (unsigned char) 1,              //system                (1 bit)
                (unsigned char) 0,              //dpl                   (2 bits)
                (unsigned char) 1,              //presetn               (1 bit)
                (unsigned char) 0x7,            //limit_16_19   	(4 bit)
                (unsigned char) 0,              //avaible               (1 bit)
                (unsigned char) 0,              //l                     (1 bit)
                (unsigned char) 1,              //d/b                   (1 bit)
                (unsigned char) 1,              //granularity   	(1 bit)
                (unsigned char) 0x00            //base_31_24    	(16 bits)
        },
       /* Descriptor de segmento de codigo user*/
        (gdt_entry){ 
                (unsigned short) 0xFFFF,        //limit 0:15    	(16 bits)
                (unsigned short) 0x0000,        //base 0:15             (16 bits)
                (unsigned char) 0x00,           //base 23:16    	(7 bits)
                (unsigned char) 0xA,            //type                  (4 bits)
                (unsigned char) 1,              //system                (1 bit)
                (unsigned char) 3,              //dpl                   (2 bits)
                (unsigned char) 1,              //present               (1 bit)
                (unsigned char) 0x7,            //limit_16_19   	(4 bit)
                (unsigned char) 0,              //avaible               (1 bit)
                (unsigned char) 0,              //l                     (1 bit)
                (unsigned char) 1,              //d/b                   (1 bit)
                (unsigned char) 1,              //granularity   	(1 bit)
                (unsigned char) 0x00            //base_31_24    	(16 bits)
        },

        /* Descriptor de segmento de datos user*/
        (gdt_entry){ 
                (unsigned short) 0xFFFF,        //limit 0:15		(16 bits)
                (unsigned short) 0x0000,        //base 0:15             (16 bits)
                (unsigned char) 0x00,           //base 23:16		(7 bits)
                (unsigned char) 0x2,            //type                  (4 bits)
                (unsigned char) 1,              //system                (1 bit)
                (unsigned char) 3,              //dpl                   (2 bits)
                (unsigned char) 1,              //presetn               (1 bit)
                (unsigned char) 0x7,            //limit_16_19   	(4 bit)
                (unsigned char) 0,              //avaible               (1 bit)
                (unsigned char) 0,              //l                     (1 bit)
                (unsigned char) 1,              //d/b                   (1 bit)
                (unsigned char) 1,              //granularity   	(1 bit)
                (unsigned char) 0x00            //base_31_24    	(16 bits)
        },
	/* segmento de video */
	(gdt_entry){ 
                (unsigned short) 0x0FBF,        //limit 0:15		(16 bits)
                (unsigned short) 0x8000,        //base 0:15             (16 bits)
                (unsigned char) 0x0B,           //base 23:16		(7 bits)
                (unsigned char) 0x2,            //type                  (4 bits)
                (unsigned char) 1,              //system                (1 bit)
                (unsigned char) 0,              //dpl                   (2 bits)
                (unsigned char) 1,              //presetn               (1 bit)
                (unsigned char) 0x0,            //limit_16_19   	(4 bit)
                (unsigned char) 0,              //avaible               (1 bit)
                (unsigned char) 0,              //l                     (1 bit)
                (unsigned char) 1,              //d/b                   (1 bit)
                (unsigned char) 0,              //granularity   	(1 bit)
                (unsigned char) 0x00            //base_31_24    	(16 bits)
        },
};

gdt_descriptor GDT_DESC = {sizeof(gdt)-1, (unsigned int)&gdt};
